﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Net.Fan.SmallPig.DataAccess;

public partial class User_Users : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            PagePermission.CheckIsAdmin(this);

            if (string.IsNullOrEmpty(Request.Params["ReturnUrl"]) == false)
            {
                HyperLinkField hl = (HyperLinkField)GridView1.Columns[0];
                hl.DataNavigateUrlFormatString = string.Format("{0}?U={1}", Request.Params["ReturnUrl"], "{0}");
            }
        }

        DataTable dd = UserDA.GetAllUsers();
        GridView1.DataSource = dd;
        GridView1.DataBind();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }

    protected void btnSelect_Click(object sender, EventArgs e)
    {
        string search;
        search = this.TBSearch.Text.Trim();
        if (!string.IsNullOrEmpty(search))
        {

            this.GridView1.DataSource = UserDA.GetUsersBySearch(search, int.Parse(this.RadioButtonList1.SelectedValue)).Tables[0];

            GridView1.DataBind();

        }
    }
}
